<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
        <%@page import="java.sql.*" %><!-- 数据库操作需要 -->   
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="UC_style.css">
<style>
#div_main1{	
	width:95%;
	background:white;
	padding:10px;
}
.sec{
	height:25px;
	width:150px;
}
.text1{
	height:25px;
	width:150px;
}
.button_Select{
		background-color:RGB(64,158,255);
    	border-width: 1px;
    	color: white;
    	padding: 5px 10px;
    	margin:10px;
    	width: 66.7px;
   	 	text-align: center;
    	font-size: 16px;
    	border-radius: 12px;
	}
.button_Select:hover {
    background-color:RGB(38,169,226);
}
.a1{
	font-size:13px;
}
.a1:hover {
    color: blue;
}
.tr1{
	background-color:white;
	font-size:12px;
}
.tr1:hover{
	background-color: RGB(160,207,255);
	
}
.tr1:hover td{background:none;}
.tr2{
	background-color:RGB(249,249,249);
	font-size:12px;
}
.tr2:hover{
	background-color: RGB(160,207,255);
	
}
.tr2:hover td{background:none;}
</style>
</head>
<body>
	<%
	String addok=(String)request.getAttribute("addok");
	if(addok!=null)
	{%>
	<script type="text/javascript">
		alert("删除成功！");
	</script>
	<% }	
	String ok= request.getParameter("ok");
	String EpID=null;
	String time=null;
	
	if(ok!=null)
	{
		EpID=request.getParameter("EpID");
		time=request.getParameter("time");
	}
	if(EpID!=null)
	{
		EpID=EpID.replace(" ", "");
		if(EpID.equals(""))
			EpID=null;
	}
	if(time!=null)
	{
		time=time.replace(" ", "");
		if(time.equals(""))
			time=null;
	}	
	if(time!=null)
	{
		if(time.charAt(5)=='0')
			time=time.substring(0, 5)+time.substring(6);
		if(time.charAt(7)=='0')
			time=time.substring(0, 7)+time.substring(8);
	}
	
	//第一个java代码段查询数据
	try{
		Class.forName("org.h2.Driver");//加载驱动
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
		return;
	}
	String url="jdbc:h2:d:/CompanyCar/temp/mydbtest";
	Connection conn=null;

//数据库连接与查询过程中可能会引发sql异常
try {
	//获取数据库连接(url,username,password)			
	conn = DriverManager.getConnection(url,"sa","");
	//准备执行数据库查询
	String sql="select * from CarRequest";
	//准备SQL执行;
	Statement stmt=conn.createStatement();
	//执行数据库查询，获取结果集
	ResultSet rs=stmt.executeQuery(sql);
	

%>	
	<div class="main" style="background-color:white " >
		
		<div id="header2">
			<img src="img/首页.png" alt="Big Boat" width="30" height="30" style=" vertical-align: middle;">
			首页>用车管理>用车审核
		</div>
		<div id="div_main1">
		<form action="#">
			<table  >
				<tr >
					<td width="300px" align="left" style="border:none;">
						<b>申请人工号</b>&nbsp;&nbsp;<input type="text" class="text1" name="EpID" >
					</td >
					<td width="600px" align="left" style="border:none">
						<b>申请日期</b>&nbsp;&nbsp;&nbsp;&nbsp;
						<input type="date" style="height:25px;width:150px;" name="time" >
					</td>
				
					<td width="300px" align="center" style="border:none">
						<input type="hidden" name="ok" value="1">
						<input type="submit" class="button_Select" id="select" value="查询">
						<!-- <input type="reset" class="button_Select"  value="重置"> -->
						
						
					</td>
				</tr>
			</table>
			</form>
		</div>
		<div id="div_main1" style="background-color:white ;">
			<table  border="1" cellspacing = "0" style="font-size:15px;">
				<tr style="background-color:RGB(228,228,228)" >
					<td height="40px"  width="300px" align="center" style="border:none">
						<b>申请编号</b>
					</td>
					<td width="400px" align="center" style="border:none">
						<b>申请人工号</b>
					</td>
					<td width="300px" align="center" style="border:none">
						<b>申请日期</b>
					</td >
					
					<td width="250px" align="center" style="border:none">
						<b>紧急程度</b>
					</td>
					
					<td width="400px" align="center" style="border:none">
						<b>用车时间</b>
					</td>
					<td width="300px" align="center" style="border:none">
						<b>乘车人数</b>
					</td>
					
					<td width="500px" align="center" style="border:none">
						<b>前往地点</b>
					</td>
					<td width="200px" align="center" style="border:none">
						<b>车牌号</b>
					</td>
					<td width="300px" align="center" style="border:none">
						<b>驾驶员</b>
					</td>
					
					<td width="300px" align="center" style="border:none">
						<b>流程状态</b>
					</td>
					
					<td width="425px" align="center" style="border:none">
						<b>操作</b>
					</td>
				</tr>
			<%	int count=0;
				while(rs!=null && rs.next())
				{ 
					String UseTime=rs.getString("UseTime");
					UseTime=UseTime.replace("T", " ");
					String RequestID=rs.getString("RequestID");
					String Status=rs.getString("Status");
					String EmpID=rs.getString("EmpID");
					String applyTime=rs.getString("applyTime");
					if(!Status.equals("审核未通过"))
							continue;
					if(EpID!=null&&time!=null)
					{	
						if(!EpID.equals(EmpID)||!time.equals(applyTime))
							continue;		
					}
					else if(EpID==null&&time!=null)
					{
						if(!time.equals(applyTime))
							continue;
					}
					else if(EpID!=null&&time==null)
					{
						if(!EpID.equals(EmpID))
							continue;
					}
					count++;
					if(count%2==1)
					{
			%>
					<tr class="tr1" >
						<td height="40px"  width="300px" align="center" style="border:none">
							<%=RequestID %>
						</td>
						<td width="300px" align="center" style="border:none">
							<%=EmpID %>
						</td>
						<td width="300px" align="center" style="border:none">
							<%=applyTime %>
						</td >
						
						<td width="250px" align="center" style="border:none">
							<%=rs.getString("degree") %>
						</td>
						
						<td width="400px" align="center" style="border:none">
							<%=UseTime%>
						</td>
						<td width="200px" align="center" style="border:none">
							<%=rs.getInt("UsersNum") %>
						</td>
						<td width="500px" align="center" style="border:none">
							<%=rs.getString("goPlace") %>
						</td>
						<td width="200px" align="center" style="border:none">
							<%=rs.getString("license_plate") %>
						</td>
						<td width="300px" align="center" style="border:none">
							<%=rs.getString("Did") %>
						</td>
						<td width="300px" align="center" style="border:none">
							<%=rs.getString("Status") %>
						</td>
						<td width="425px" align="center" style="border:none">
							<a class="a1" >查看</a>
							<%String checkURL="C-UseCar_CheckList.jsp?RequestID="+RequestID; %>
							<a class="a1" href=<%=checkURL %>>重新审核</a>
							<%String deleteURL="C-jdbc-AdminDelete.jsp?RequestID="+RequestID; %>
							<a class="a1" style="color:red" href=<%=deleteURL %>>删除</a>
						</td>
					</tr>
					<%}else{ %>
						<tr class="tr2" >
						<td height="40px"  width="300px" align="center" style="border:none">
							<%=RequestID %>
						</td>
						<td width="300px" align="center" style="border:none">
							<%=EmpID %>
						</td>
						<td width="300px" align="center" style="border:none">
							<%=applyTime %>
						</td >
						
						<td width="250px" align="center" style="border:none">
							<%=rs.getString("degree") %>
						</td>
						
						<td width="400px" align="center" style="border:none">
							<%=UseTime%>
						</td>
						<td width="200px" align="center" style="border:none">
							<%=rs.getInt("UsersNum") %>
						</td>
						<td width="500px" align="center" style="border:none">
							<%=rs.getString("goPlace") %>
						</td>
						<td width="200px" align="center" style="border:none">
							<%=rs.getString("license_plate") %>
						</td>
						<td width="300px" align="center" style="border:none">
							<%=rs.getString("Did") %>
						</td>
						<td width="300px" align="center" style="border:none">
							<%=rs.getString("Status") %>
						</td>
						<td width="425px" align="center" style="border:none">
							<a class="a1" >查看</a>
							<%String checkURL="C-UseCar_CheckList.jsp?RequestID="+RequestID; %>
							<a class="a1" href=<%=checkURL %>>重新审核</a>
							<%String deleteURL="C-jdbc-AdminDelete.jsp?RequestID="+RequestID; %>
							<a class="a1" style="color:red" href=<%=deleteURL %>>删除</a>
						</td>
					</tr>
					<%} %>
			<%} %>							
			</table>
		</div>
	</div>
<%
	//关闭表达式对象
	stmt.close();			
	//关闭数据库			
	conn.close();			
	
} catch (SQLException e) {
	e.printStackTrace();
} finally{
	//防止数据库未正常关闭
	try{
		if (conn!=null && (!conn.isClosed())){
			conn.close();
		}
	}catch(SQLException e){
		e.printStackTrace();
	}
}
%>
</body>
</html>